package pl.dmcs.grails

import pl.dmcs.grails.planner.PlannerEvent
import pl.dmcs.grails.security.User

class Employee extends User {

    private static final avatarTypes = ['image/png', 'image/jpeg']
    static hasMany = [plannerEvents : PlannerEvent, employeeCategories : EmployeeCategory]
    static belongsTo = EmployeeCategory
    
    static mapping = {
        plannerEvents lazy: false
        sort "lastName" //sort employess by the lastName in the oneToMany relationships
    }
    
    String firstName
    String lastName
    String title
    String email
    String room
    byte[] avatar
    String avatarType

    static constraints = {
        title blank:true, nullable: true
        email email:true, unique: true
        avatar nullable:true 
        avatarType nullable:true
    }
    
    def getFullName() {
        "${title?:''} $firstName $lastName"
    }
}
